//
//  btnCollCell.m
//  CollectionText
//
//  Created by heyong on 16/6/25.
//  Copyright © 2016年 ttsx. All rights reserved.
//
#define w [UIScreen mainScreen].bounds.size.width

#import "btnCollCell.h"
@implementation btnCollCell
- (NSMutableArray *)dataArray{
    if(_dataArray==nil){
        _dataArray=[NSMutableArray arrayWithCapacity:0];
    }
    return _dataArray;
}
- (UIButton *)btn{
    if(_btn==nil){
        _btn=[[UIButton alloc]initWithFrame:CGRectMake(0, 0,self.contentView.frame.size.width, self.contentView.frame.size.height)];
        _btn.backgroundColor=[UIColor colorWithRed:0.93 green:0.93 blue:0.94 alpha:1.00];
        _btn.layer.cornerRadius=4.;
        _btn.titleLabel.font=[UIFont boldSystemFontOfSize:13.];
        [_btn setTitleColor:[UIColor colorWithRed:0.32 green:0.33 blue:0.33 alpha:1.00] forState:UIControlStateNormal];
        [_btn setTitleColor:[UIColor whiteColor] forState:UIControlStateSelected];
        [_btn addTarget:self action:@selector(clickBtn:) forControlEvents:UIControlEventTouchUpInside];
    }
    return _btn;
}

- (instancetype)initWithFrame:(CGRect)frame{
    self=[super initWithFrame:frame];
    if(self){
        [self.contentView addSubview:self.btn];
    }
    return self;
}

- (void)setCollBtnTitle:(NSString *)titie andId:(NSString *)btnId{
    [self.btn setTitle:titie forState:UIControlStateNormal];
}


- (void)clickBtn:(UIButton *)sender{
    sender.selected=!sender.selected;
    //title传递过去
    if(self.clickBtnBlock){
        self.clickBtnBlock([sender currentTitle]);
    }
    //根据状态修改背景颜色
    if(sender.selected){
        sender.backgroundColor=[TTTheme defaultManger].selectColor;
    }else{
        sender.backgroundColor=[UIColor colorWithRed:0.93 green:0.93 blue:0.94 alpha:1.00];
        [self.dataArray removeObject:[sender currentTitle]];
    }
}
@end
